<template>
    <div>
        <div class="box">
            <horder class="horder">
                <p style="float: left;margin: 0 50px 0 0;color: #ccc;">中文(简体)</p>
                <p style="float: right;margin: -5px 0 0 0;color: #ccc;">帮助</p>
            </horder>
            <main class="main">
                <h2 style="text-align: center;">小米账号登录</h2>
                <p
                    style="width: 80px;height: 80px;background: orange;font-size: 50px;color: aliceblue;text-align: center;margin-top: 20px;border-radius: 25%;margin-left: 140px;">
                    ml</p>
                <h3 style="color: #ccc;text-align: center;">让每个人都能享受科技的快乐</h3>

                <!-- 登录 -->
                <van-form @submit="onSubmit">
                    <van-cell-group inset>
                        <van-field v-model="username" name="username" label="用户名" placeholder="用户名" :rules="[{ required: true, message: '请填写用户名' }, { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号' }
                        ]" />
                        <van-field v-model="password" type="password" name="password" label="密码" placeholder="密码"
                            :rules="[{ required: true, message: '请填写密码' }, { pattern: /^\d{6}$/, message: '请输入6位数字' }]" />
                    </van-cell-group>
                    <div style="margin: 16px;">
                        <van-button round block type="primary" native-type="submit">
                            提交
                        </van-button>
                    </div>
                </van-form>
            </main>
        </div>
    </div>
</template>

<script setup>
import api from '@/api/api'

import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

import { ref } from 'vue';


const username = ref('');
const password = ref('');
const onSubmit = (values) => {
    api.post('/login', values).then(res => {
        if (res.data.code == 200) {
            showSuccessToast('登录成功')
            localStorage.setItem('token', res.data.token)
            localStorage.setItem('username', username.value)
            router.push('/')
        } else {
            showFailToast('登录失败');
        }
    })
};

;
</script>

<style lang="scss" scoped></style>